home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Orlando_1993 / Devcon93.1 / IFF / newiff39 / modules / loadilbm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  5.5 KB  |  220 lines

  1. /* loadilbm.c - C. Scheppner CBM
  2.  *
  3.  * High-level ILBM load routines
  4.  *
  5.  * 37.9  04/92 - use vp->ColorMap.Count instead of MAXAMCOLORREG
  6.  * 37.10 07/92 - use scr->RastPort.BitMap instead of &scr->BitMap
  7.  *            for future compatibility
  8.  * 39.1  07/92 - add support for V39 color loading functions
  9.  */
  10. #define INTUI_V36_NAMES_ONLY
  11.  
  12. #include "iffp/ilbm.h"
  13. #include "iffp/ilbmapp.h"
  14.  
  15. extern struct Library *GfxBase;
  16.  
  17. /* loadbrush
  18.  *
  19.  * Passed an initialized ILBMInfo with a not-in-use ParseInfo.iff
  20.  *   IFFHandle and desired propchks, collectchks, and stopchks, and filename,
  21.  *   will load an ILBM as a brush, setting up ilbm->Bmhd, ilbm->camg,
  22.  *   ilbm->brbitmap, ilbm->colortable, and ilbm->ncolors
  23.  *
  24.  *   Note that ncolors may be more colors than you can LoadRGB4.
  25.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  26.  *   you change the colors yourself using 1.3/2.0 functions.
  27.  *
  28.  * V39 - unless ilbm->IFFPFlags & IFFPF_NOCOLOR32, will do 32-bit
  29.  *   color load under V39 and higher
  30.  *
  31.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  32.  */
  33.  
  34. LONG loadbrush(struct ILBMInfo *ilbm, UBYTE *filename)
  35. {
  36. LONG error = 0L;
  37.  
  38.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  39.  
  40.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  41.     {
  42.     error = parseifile((struct ParseInfo *)ilbm,
  43.                 ID_FORM, ID_ILBM,
  44.                 ilbm->ParseInfo.propchks,
  45.                 ilbm->ParseInfo.collectchks,
  46.                 ilbm->ParseInfo.stopchks);
  47.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  48.         {
  49.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  50.         {
  51.             if(error = createbrush(ilbm))   deletebrush(ilbm);
  52.         }
  53.         else
  54.         {
  55.         message(SI(MSG_ILBM_NOILBM));
  56.         error = NOFILE;
  57.         }
  58.         }
  59.     if(error)    closeifile((struct ParseInfo *)ilbm);
  60.     }
  61.     return(error);
  62. }
  63.  
  64.  
  65. /* unloadbrush
  66.  *
  67.  * frees and close everything alloc'd/opened by loadbrush
  68.  */
  69. void unloadbrush(struct ILBMInfo *ilbm)
  70. {
  71.     deletebrush(ilbm);
  72.     closeifile((struct ParseInfo *)ilbm);
  73. }
  74.  
  75.  
  76. /* queryilbm
  77.  *
  78.  * Passed an initilized ILBMInfo with a not-in-use IFFHandle,
  79.  *   and a filename,
  80.  *   will open an ILBM, fill in ilbm->camg and ilbm->bmhd,
  81.  *   and close the ILBM.
  82.  *
  83.  * This allows you to determine if the ILBM is a size and
  84.  *   type you want to deal with.
  85.  *
  86.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  87.  */
  88.  
  89. /* query just wants these chunks */
  90. LONG queryprops[] = { ID_ILBM, ID_BMHD,
  91.               ID_ILBM, ID_CAMG,
  92.                       TAG_DONE };
  93.  
  94. /* scan can stop when a CMAP or BODY is reached */
  95. LONG querystops[] = { ID_ILBM, ID_CMAP,
  96.               ID_ILBM, ID_BODY,
  97.               TAG_DONE };
  98.  
  99. LONG queryilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  100. {
  101. LONG error = 0L;
  102. BitMapHeader *bmhd;
  103.  
  104.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  105.  
  106.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  107.     {
  108.     D(bug("queryilbm: openifile successful\n"));
  109.  
  110.     error = parseifile((struct ParseInfo *)ilbm,
  111.             ID_FORM, ID_ILBM,
  112.             queryprops, NULL, querystops);
  113.  
  114.     D(bug("queryilbm: after parseifile, error = %ld\n",error));
  115.  
  116.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  117.         {
  118.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  119.         {
  120.         if(bmhd = (BitMapHeader*)
  121.             findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD))
  122.             {
  123.             *(&ilbm->Bmhd) = *bmhd;
  124.             ilbm->camg = getcamg(ilbm);
  125.             }
  126.         else error = NOFILE;
  127.         }
  128.         else
  129.         {
  130.         message(SI(MSG_ILBM_NOILBM));
  131.         error = NOFILE;
  132.         }
  133.         }
  134.     closeifile(ilbm);
  135.     }
  136.     return(error);
  137. }
  138.  
  139.  
  140. /* loadilbm
  141.  *
  142.  * Passed a not-in-use IFFHandle, an initialized ILBMInfo, and filename,
  143.  *   will load an ILBM into your already opened ilbm->scr, setting up
  144.  *   ilbm->Bmhd, ilbm->camg, ilbm->colortable, and ilbm->ncolors
  145.  *   and loading the colors into the screen's viewport
  146.  *
  147.  *   Note that ncolors may be more colors than you can LoadRGB4.
  148.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  149.  *   you change the colors yourself using 1.3/2.0 functions.
  150.  *
  151.  * V39 - unless ilbm->IFFPFlags & IFFPF_NOCOLOR32, will do 32-bit
  152.  *   color load under V39 and higher
  153.  *
  154.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  155.  *
  156.  * NOTE - loadilbm() keeps the IFFHandle open so you can copy
  157.  *   or examine other chunks.  You must call closeifile(iff,ilbm)
  158.  *   to close the file and deallocate the parsed context
  159.  *
  160.  */
  161.  
  162. LONG loadilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  163. {
  164. LONG error = 0L;
  165.  
  166.  
  167.     D(bug("loadilbm:\n"));
  168.  
  169.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  170.     if(!ilbm->scr)        return(CLIENT_ERROR);
  171.     if(!(ilbm->vp))        ilbm->vp = &ilbm->scr->ViewPort;  /* 39.1 */
  172.  
  173.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  174.     {
  175.     D(bug("loadilbm: openifile successful\n"));
  176.  
  177.     error = parseifile((struct ParseInfo *)ilbm,
  178.             ID_FORM, ID_ILBM,
  179.             ilbm->ParseInfo.propchks,
  180.             ilbm->ParseInfo.collectchks,
  181.             ilbm->ParseInfo.stopchks);
  182.  
  183.     D(bug("loadilbm: after parseifile, error = %ld\n",error));
  184.  
  185.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  186.         {
  187.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  188.         {
  189.             error = loadbody(ilbm->ParseInfo.iff,
  190.                 ilbm->scr->RastPort.BitMap, &ilbm->Bmhd);
  191.  
  192.         D(bug("loadilbm: after loadbody, error = %ld\n",error));
  193.  
  194.         if(!error)
  195.             {
  196.             if(!(getcolors(ilbm)))    setcolors(ilbm,ilbm->vp);
  197.             }
  198.         }
  199.         else
  200.         {
  201.         message(SI(MSG_ILBM_NOILBM));
  202.         error = NOFILE;
  203.         }
  204.         }
  205.     if(error)    closeifile((struct ParseInfo *)ilbm);
  206.     }
  207.     return(error);
  208. }
  209.  
  210.  
  211. /* unloadilbm
  212.  *
  213.  * frees and closes everything allocated by loadilbm
  214.  */
  215. void unloadilbm(struct ILBMInfo *ilbm)
  216. {
  217.     closeifile((struct ParseInfo *)ilbm);
  218.     freecolors(ilbm);
  219. }
  220.